package com.example.examadmin.service;

import com.example.examadmin.entity.Admin;
import com.example.examadmin.service.AdminMapper;
import com.example.examadmin.service.AdminService;
import com.example.examadmin.service.Service;
import com.example.examadmin.service.ServiceImpl;

import javax.management.Query;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Override
    public boolean login(String username, String password) {
        // 从数据库查询管理员，校验账号密码
        Admin admin = lambdaQuery().eq(Admin::getUsername, username).one();
        return admin != null && admin.getPassword().equals(password);
    }

    private Query lambdaQuery() {
    }

    @Override
    public boolean changePassword(Long adminId, String oldPwd, String newPwd) {
        Admin admin = getById(adminId);
        if (admin != null && admin.getPassword().equals(oldPwd)) {
            admin.setPassword(newPwd);
            return updateById(admin);
        }
        return false;
    }

    private boolean updateById(Admin admin) {
    }

    private Admin getById(Long adminId) {
    }
}